import { IModalConfig } from '@/components/page-modal/type'
import { FormType } from '@/base-ui/base-form/type'
import { ActionDesc, PagesKey } from '@/global/constant'

const getQuestionModalAddOrEdit = (isAdd = true): IModalConfig => {
  const config: IModalConfig = {
    modalProps: {
      title: isAdd ? '新增分类' : '编辑分类',
      width: 500,
      maskClosable: false,
      closable: false
    },
    formProps: {
      pageKey: PagesKey.ClassifyQuestion,
      desc: isAdd ? ActionDesc.Add : ActionDesc.Edit,
      layout: { span: 24 },
      formConfig: {
        name: isAdd ? 'question-manage-add' : 'question-manage-edit',
        initialValues: {
          // type: 0
        },
        size: 'small',
        labelAlign: 'right',
        // labelCol: 输入框这些前面的文字的宽度
        labelCol: { flex: '85px' },
        // labelWrap：表单前面的label宽度(labelCol指定的flex)不够,那么他会进行自动换行
        // labelWrap: true,
        // wrapperCol: { flex: 1 },
        colon: false
        // style: { minWidth: 700 }
      },
      itemsConfig: [
        {
          type: FormType.Custom,
          prop: 'parentId',
          name: 'parentId',
          customkey: 'parentId',
          label: '上级分类',
          rules: isAdd ? [{ required: true }] : []
        },
        {
          type: FormType.Radio,
          prop: 'classifyType',
          name: 'classifyType',
          label: '分类',
          rules: isAdd ? [{ required: true }] : [],
          radio: {
            baseProps: {
              disabled: true
            },
            options: [
              { value: 0, content: '一级' },
              { value: 1, content: '二级' },
              { value: 2, content: '三级' }
            ]
          }
        },
        {
          type: FormType.Input,
          prop: 'name',
          name: 'name',
          label: '分类名称',
          rules: isAdd ? [{ required: true }] : [],
          input: {
            placeholder: '请输入分类名称'
          }
        },
        {
          type: FormType.Input,
          prop: 'svgName',
          name: 'svgName',
          label: '图标名称',
          rules: isAdd ? [{ required: true }] : [],
          input: {
            placeholder: '请输入图标名称'
          }
        }
      ]
    }
  }
  return config as IModalConfig
}

export default getQuestionModalAddOrEdit
